<!-- class: title-slide, right, top --> <!-- background-image: url(img/front-page.png) --> <!-- background-position: 90% 75%, 75% 75% --> <!-- background-size:cover --> <!-- .palegrey[.left[.footnote[Graphic by [Elaine Hickey](https://photos.google.com/photo/AF1QipMjKNoaxyne8nte4HmxA6Th9-4fUfSbl_mx-_1G)]]] --> <!-- ??? --> <!-- Welcome to the workshop on ggplot. --> <!-- Where we'll show you how to create impressive data visualisations. --> <!-- --- --> <!-- name: about-me --> <!-- layout: false --> <!-- class: about-me-slide, inverse, middle, center --> <!-- # About me --> <!-- <img style="border-radius: 50%;" src="data:image/png;base64,#img/eugene.jpg" width="150px"/> --> <!-- ## Eugene Hickey --> <!-- ### lecturer in physics --> <!-- .fade[Technological University<br>Dublin] --> <!-- [
bioscience.netlify.app](https://bioscience.netlify.app) --> <!-- [
@eugene100hickey](https://twitter.com/eugene100hickey) --> <!-- [
eugene100hickey](https://github.com/eugene100hickey) --> <!-- --- --> <!-- layout: true --> <!-- <a class="footer-link" href="http://bit.ly/xaringan-nhsr">bit.ly/xaringan-nhsr — Silvia Canelón</a> --> <!-- <!-- this adds the link footer to all slides, depends on footer-link class in css--> --> <!-- --- --> <!-- class: top --> <!-- # Acknowledgments --> <!-- .pull-left-narrow[.center[<img style="border-radius: 50%;" src="data:image/png;base64,#https://lauriebaker.rbind.io/author/dr.-laurie-baker/avatar_hu30116ce9545207e6cc07ea892252ff02_106302_270x270_fill_q90_lanczos_center.jpg" width="100px"/>]] --> <!-- .pull-right-wide[ --> <!-- [Laurie Baker](https://lauriebaker.rbind.io), co-pilot for this workshop and Data Science Lecturer at the Data Science Campus, Office for National Statistics, UK.as --> <!-- ] --> <!-- -- --> <!-- .pull-left-narrow[.center[ --> <!-- <img style="border-radius: 50%;" src="data:image/png;base64,#https://avatars0.githubusercontent.com/u/53170984?s=200&v=4" width="125px"/>]] --> <!-- .pull-right-wide[ --> <!-- [NHS-R Community](https://nhsrcommunity.com/) for the opportunity to provide this workshop --> <!-- - [nhsrtheme 📦](https://github.com/nhs-r-community/nhsrtheme) developed by Tom Jemmett --> <!-- - [NHSRdatasets 📦](https://github.com/nhs-r-community/NHSRdatasets) developed by Chris Mainey --> <!-- ] --> <!-- -- --> <!-- .pull-left-narrow[.center[ --> <!--
]] --> <!-- .pull-right-wide[ --> <!-- - [xaringan 📦](https://github.com/yihui/xaringan#xaringan) developed by Yihui Xie --> <!-- - [xaringanExtra 📦](https://github.com/gadenbuie/xaringanExtra/#xaringanExtra) developed by Garrick Aden-Buie --> <!-- - Materials developed by [Alison Hill](https://twitter.com/apreshill) that have inspired and informed this workshop --> <!-- ] --> <!-- --- --> --- # Target Audience - people with some experience of R, but haven't made the plunge to ggplot. __Just yet__. - do data analysis in R and provide visualisations using base graphics, or something else. --- # Why ggplot? - while some plots can be easier to produce using base graphics .pull-left[ ```r hist(LOS_model$Age) ``` <img src="data:image/png;base64,#day-01-basics_files/figure-html/base_hist-1.png" width="80%" /> ] .pull-right[ ```r ggplot(data = LOS_model, aes(Age)) + geom_histogram() ``` <img src="data:image/png;base64,#day-01-basics_files/figure-html/ggplot_hist-1.png" width="80%" /> ] --- # Why ggplot? - anything moderately complicated is better in ggplot .pull-left[ ```r # David Robinson # http://varianceexplained.org/r/why-I-use-ggplot2/ par(mar = c(1.5, 1.5, 1.5, 1.5)) colors <- 1:6 names(colors) <- unique(top_data$nutrient) # legend approach from http://stackoverflow.com/a/10391001/712603 m <- matrix(c(1:20, 21, 21, 21, 21), nrow = 6, ncol = 4, byrow = TRUE) layout(mat = m, heights = c(.18, .18, .18, .18, .18, .1)) top_data$combined <- paste(top_data$name, top_data$systematic_name) for (gene in unique(top_data$combined)) { sub_data <- filter(top_data, combined == gene) plot(expression ~ rate, sub_data, col = colors[sub_data$nutrient], main = gene) for (n in unique(sub_data$nutrient)) { m <- lm(expression ~ rate, filter(sub_data, nutrient == n)) if (!is.na(m$coefficients[2])) { abline(m, col = colors[n]) } } } # create a new plot for legend plot(1, type = "n", axes = FALSE, xlab = "", ylab = "") legend("top", names(colors), col = colors, horiz = TRUE, lwd = 4) ``` ] .pull-right[ <!-- --> ] --- # Why ggplot? - anything moderately complicated is better in ggplot .pull-left[ ```r ggplot(top_data, aes(rate, expression, color = nutrient)) + geom_point(show.legend = FALSE) + geom_smooth(method = "lm", se = FALSE, show.legend = FALSE) + facet_wrap(~systematic_name, scales = "free_y") ``` ] .pull-right[ <!-- --> ] --- # Lots of addin packages for ggplot gg.gap, ggallin, ggalluvial, ggalt, ggamma, gganimate, ggasym, ggbeeswarm, ggBubbles, ggbuildr, ggbump, ggcharts, ggChernoff, ggconf, ggcorrplot, ggdag, ggdark, ggDCA, ggdemetra, ggdendro, ggdist, ggdmc, gge, ggeasy, ggedit, ggeffects, ggenealogy, ggetho, ggExtra, ggfan, ggfittext, ggfocus, ggforce, ggformula, ggfortify, gggap, gggenes, ggghost, gggibbous, ggguitar, gghalfnorm, gghalves, gghighlight, ggimage, ggimg, gginference, gginnards, ggip, ggiraph, ggiraphExtra, ggjoy, gglasso, gglm, gglogo, ggloop, gglorenz, ggm, ggmap, ggmcmc, ggmix, ggmosaic, ggmr, ggmsa, ggmuller, ggmulti, ggnetwork, ggnewscale, ggnormalviolin, ggnuplot, ggpacman, ggpage, ggparallel, ggparliament, ggparty, ggperiodic, ggplot.multistats, ggplot2, ggplot2movies, ggplotAssist, ggplotgui, ggplotify, ggplotlyExtra, ggpmisc, ggPMX, ggpointdensity, ggpol, ggpolypath, ggpubr, ggpval, ggQC, ggQQunif, ggquickeda, ggquiver, ggRandomForests, ggraph, ggraptR, ggrasp, ggrastr, ggrepel, ggResidpanel, ggridges, ggrisk, ggROC, ggroups, ggsci, ggseas, ggseqlogo, ggsignif, ggsn, ggsoccer, ggsolvencyii, ggsom, ggspatial, ggspectra, ggstance, ggstar, ggstatsplot, ggstudent, ggswissmaps, ggtern, ggtext, ggThemeAssist, ggthemes, ggTimeSeries, ggupset, ggVennDiagram, ggversa, ggvis, ggvoronoi, ggwordcloud --- # And others, that make ggplots that can then be modified and treated as such .pull-left[ ```r fviz_cluster_example ``` <!-- --> ] .pull-right[ ```r fviz_cluster_example + theme_classic() ``` <!-- --> ]